--[[
*名称:DesktopLayer
*描述:游戏层
*版权:Copyright © 2016-2018 深圳市三只小熊科技有限公司 版权所有
*作者:管理员
*创建日期:
*修改日期:
*备注:该类属于baseClsss请勿修改，如需修改请详询管理员
]]
local DesktopLayer = class("DesktopLayer", PokerViewBase)
local CURRENT_MODULE_NAME = ...
--[[
 界面处理需要保证就算是错误数据也做到不崩溃
 在获取到数据的时候进行checkData操作
]]
function DesktopLayer:onCreate(owner)
	Log.d("DesktopLayer:onCreate");
	self:initWithFilePath("desktoplayer", CURRENT_MODULE_NAME);

	self:_initialize();
end

function DesktopLayer:_initialize(  )
	self._hasClicked = false;
	self.bgShake = self.node.bg_shake;
	self._touchListener = cc.EventListenerTouchOneByOne:create();
    self._touchListener:setSwallowTouches(true);
	self._touchListener:registerScriptHandler(handler(self, DesktopLayer._onTouchBegan), cc.Handler.EVENT_TOUCH_BEGAN);
	self.bgShake:getEventDispatcher():addEventListenerWithFixedPriority(self._touchListener, 2)
end
function DesktopLayer:_onTouchBegan(  )
	if self._hasClicked then 
		-- double clicked
		local diffTime = os.time() - self._firstTime;
		if diffTime >= 0 and diffTime < 2 then 
			self:_doubleDesktopClicked();
		end
		self._firstTime = nil;
		self._hasClicked = false;
	else 
		self._firstTime = os.time();
		self._hasClicked = true;
	end
	return true;
end
---
 -- 物理返回键事件
 -- @DateTime 2017-09-25
 -- @return   nil
 -- 
function DesktopLayer:backEvent()
 	-- DesktopLayer.super.backEvent(self);
end
---
 -- 抖动桌面
function DesktopLayer:shakeDesktop()
	AnimUtils.shakeDesktop(self.node.bg_shake);
end

function DesktopLayer:_doubleDesktopClicked(  )
	self:callPartMethod("doubleDesktopClicked");
end

function DesktopLayer:onExit(  )
	if self.bgShake and self._touchListener then 
		self.bgShake:getEventDispatcher():removeEventListener(self._touchListener);
	end
end

return DesktopLayer